package net.zjitc.controller.client;

import net.zjitc.pojo.District;
import net.zjitc.pojo.Movie;
import net.zjitc.pojo.Types;
import net.zjitc.service.DistrictService;
import net.zjitc.service.MovieService;
import net.zjitc.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author admin
 * @Date 2019/5/27 10:21
 */
//电影
@Controller
@RequestMapping(value = "/films")
public class FilmsController {
    @Autowired
    TypeService typeService;
    @Autowired
    DistrictService districtService;
    @Autowired
    MovieService movieService;

    @RequestMapping(value = "/index")
    public String index(HttpServletRequest request,Model model){
        head(model);
        List<Movie>hotList = movieService.findByhot();
        model.addAttribute("MovieList",hotList);
        return "/client/films";
    }

//    分类查询--》电影页面
    @RequestMapping(value = "/dis")
    public String films(HttpServletRequest request, Model model){
        head(model);
        Integer dis_id = Integer.parseInt(request.getParameter("dis_id"));
        List<Movie>DisList = movieService.findByDis_id(dis_id);
        model.addAttribute("MovieList",DisList);
        return "/client/films";
    }
    @RequestMapping(value = "/type")
    public String type(HttpServletRequest request, Model model){
        head(model);
        Integer type_id = Integer.parseInt(request.getParameter("type_id"));
        List<Movie>TypeList = movieService.findByType_id(type_id);
        model.addAttribute("MovieList",TypeList);
        return "/client/films";
    }

//    三大巨头
    @RequestMapping(value = "/show")
    public String show(HttpServletRequest request,Model model){
        head(model);
        int showType = Integer.parseInt(request.getParameter("showType"));
        List<Movie> list  = movieService.show(showType);
        model.addAttribute("MovieList",list);
        return "/client/films";
    }

    //电影详情页面
    @RequestMapping(value = "/details")
    public String details(HttpServletRequest request,Model model){
        int movie_id = Integer.parseInt(request.getParameter("movie_id"));
        Movie movie = movieService.findById(movie_id);
        model.addAttribute("movie",movie);
        return "/client/movie";
    }

    public void head(Model model){
        List<Types> types_list = typeService.findAll();
        List<District> dis_list = districtService.findAll();
        model.addAttribute("t_list", types_list);
        model.addAttribute("d_list",dis_list);
    }
}
